package com.digitalart.futbol.hibernate.daoImpl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.digitalart.futbol.hibernate.dao.LocalDao;
import com.digitalart.futbol.hibernate.ejb.Local;

@Repository
public class LocalDaoImpl implements LocalDao{

	@Autowired(required=true)
	private SessionFactory sessionFactory;
	
	@Transactional
	public  Local findById(int id){
		
		String queryString= "from Local local where local.id_local=?";
		
		Local result = (Local) this.sessionFactory.getCurrentSession().createQuery(queryString).setParameter(0, id).uniqueResult();	
		
		return result;
		
	}
	
	@Transactional
	public Local persistOnMerge (Local objLocal){
		Local result = (Local)this.sessionFactory.getCurrentSession().merge(objLocal);
		
		return result;
	}

	@Override
	public List<Local> findAll() {
		String queryString= "from Local local";

		List<Local> result = (List) this.sessionFactory.getCurrentSession().createQuery(queryString).list();	

		return result;
	}
	
}
